//
//  PersonInfoCell.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/2/7.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "PersonInfoCell.h"


@interface PersonInfoCell()

/// rightButton的宽度大于高度多少
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightButton_width;

@property (copy, nonatomic) CellBtnBlock buttonBlock;

@end

@implementation PersonInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.rightButton.imageView.contentMode =UIViewContentModeScaleAspectFill;
}

- (void)setIndexPath:(NSIndexPath *)indexPath {
    _indexPath =indexPath;
    
    if (indexPath.section ==0 && indexPath.row ==0) {
        self.rightButton_width.constant =0;
        self.rightButton.cornerRadius =CGRectGetHeight(self.rightButton.frame)/2.0;
        [self.rightButton setTitle:@"" forState:UIControlStateNormal];
        [self.rightButton setImage:[UIImage imageNamed:@"touxiang"] forState:UIControlStateNormal];
        self.accessoryType =UITableViewCellAccessoryNone;
    } else {
        self.rightButton_width.constant =100;
        self.rightButton.cornerRadius =1.0;
        [self.rightButton setTitle:@"点击修改昵称" forState:UIControlStateNormal];
        [self.rightButton setImage:[UIImage imageNamed:@"clear_action"] forState:UIControlStateNormal];
        self.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if ([self.rightButton.currentTitle isEqualToString:@"点击修改昵称"] ||
        isStringEmpty(self.rightButton.currentTitle)) {
        [self.rightButton setTitleColor:[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.00] forState:UIControlStateNormal];
    } else {
        [self.rightButton setTitleColor:self.nameLabel.textColor forState:UIControlStateNormal];
    }

}

/// 创建cell
+ (instancetype)findCellWithIdentifier:(NSString*)identifier {
    NSArray *cellArray =[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil];
    for (PersonInfoCell *cell in cellArray) {
        if ([cell.reuseIdentifier isEqualToString:identifier]) {
            return cell;
        }
    }
    return nil;
}

- (IBAction)rightButtonClick:(UIButton*)sender {
    if (self.buttonBlock) {
        self.buttonBlock(sender, self.indexPath);
    }
}

- (void)didButtonClickBlock:(CellBtnBlock)newBlock {
    self.buttonBlock = newBlock;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
